﻿function viewstudentLink_clicked()
{
	$("#hidestudentLink").removeClass("hideA");
	$("#viewstudentDiv").removeClass("hideA");
	}
function hidestudentLink_clicked()
{
	$("#hidestudentLink").addClass("hideA");
	$("#viewstudentDiv").addClass("hideA");
	}
function getPWDLink_clicked()
{
	$("#hidePWDLink").removeClass("hideA");
	$("#viewPWDDiv").removeClass("hideA");	
}
function hidePWDLink_clicked()
{
	$("#hidePWDLink").addClass("hideA");
	$("#viewPWDDiv").addClass("hideA");
}
function showStudent_clicked()
{
	var choise=$("#showStudentOption").val();
	$.ajax({
            type: 'Post',
            url: '/mnguser_action_searchStudent',
            data: "choise="+choise,
			dataType:"json",
            success: function(response) {
                resloveMessage(response);
            	}
        	})	
}

function resloveMessage(msg)
{
	if(msg=='failed')
		alert('系统原因，查找失败');
	else
		BuildUpStudentTable(msg)
	}
function BuildUpStudentTable(data)
{
	$("#table_student").find("tr[id!='header']&&[id!='template']").remove();
	var table=$("#table_student")
	$(data).each(function(i){
			var row = $("#table_student").find('#template').clone();
			$(row).find("#studentMail").find("div").html(this.studentMail);
			$(row).find("#className").find("div").html(this.className);
			$(row).find("#studentNumber").find("div").html(this.studentNumber);
			$(row).find("#studentName").find("div").html(this.studentName);
			if(this.studentSex==0)
				$(row).find("#studentSex").text('男');
			else
				$(row).find("#studentSex").text('女');
			$(row).attr("id","ready");
			$(row).removeClass("hiddenTd");
			if(i%2==0)
			{
				$(row).addClass("colorTr");
				}
            row.appendTo(table);
			})
	}
	
function studentDelete_clicked(sender)
{
	var tr=$(sender).parent().parent();
	studentNumber=$(tr).find("#studentNumber").find("div").html();
	alert(studentNumber)
	$.ajax({
            type: 'Post',
            url: '/mnguser_action_deleteStudent',
            data: "studentNumber="+studentNumber,
            success: function(response) {
                alert(response);
            	showStudent_clicked();
				}
        	})
	
	}

function searchStuByNumber()
{
	var stuNumber=$("#searchPwdStuNumber").val();
	if(!CheckNumber(stuNumber))
	{
		alert("输入数字~");	
	}
	else
	{
		$.ajax({
            type: 'Post',
            url: '/mnguser_action_searchStudentByNumber',
            data: "studentNumber="+stuNumber,
            success: function(response) {
                alert(response);
				}
        	})
	}
}
function resetPassword()
{
	var stuNumber=$("#searchPwdStuNumber").val();
	if(!CheckNumber(stuNumber))
	{
		alert("输入数字~");	
	}
	else
	{
		$.ajax({
            type: 'Post',
            url: '/mnguser_action_resetPasswordByStudentNymber',
            data: "studentNumber="+stuNumber,
            success: function(response) {
                alert(response);
				}
        	})
	}
}
function CheckNumber(num)
{
	var patrn=/^[0-9]*[1-9][0-9]*$/;
	if   (!patrn.exec(num))     
	  return false;  
	else 
	  return true;  
}